
package kaizone.haining.chaobohui.fragment;

import kaizone.haining.chaobohui.R;
import kaizone.haining.chaobohui.activity.CBHActivity;
import kaizone.haining.chaobohui.util.Utils;
import kaizone.haining.chaobohui.widget.CBHHead;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

public class CBHMenu extends Fragment implements OnClickListener {
    private FragmentManager mFragmentManager;

    private CBHHead mCbhHead;

    private TextView mHomeTextView;

    private TextView mInfoTextView;

    private TextView mHistoryTextView;

    private TextView mTopicTextView;

    private TextView mFristReadTextView;

    private TextView mAboutTextView;

    public CBHMenu() {
        // TODO Auto-generated constructor stub
    }

    public CBHMenu(FragmentManager mgr) {
        mFragmentManager = mgr;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = (View) inflater.inflate(R.layout.cbh_fragment_menu, null);
        mCbhHead = (CBHHead) view.findViewById(R.id.head);
        mHomeTextView = (TextView) view.findViewById(R.id.menu_1);
        mInfoTextView = (TextView) view.findViewById(R.id.menu_2);
        mHistoryTextView = (TextView) view.findViewById(R.id.menu_3);
        mTopicTextView = (TextView) view.findViewById(R.id.menu_4);
        mFristReadTextView = (TextView) view.findViewById(R.id.menu_5);
        mAboutTextView = (TextView) view.findViewById(R.id.menu_6);
        initmenu();
        return view;
    }

    private void initmenu() {
        mCbhHead.setMenuVisibility(View.INVISIBLE);
        String text = getResources().getString(R.string.menu_bt);
        mCbhHead.setText(text);
        int textcolor = getResources().getColor(R.color.white);
        mCbhHead.setTextColor(textcolor);
        int bgcolor = getResources().getColor(R.color.black);
        mCbhHead.setBackgroundColor(bgcolor);

        mHomeTextView.setOnClickListener(this);
        mInfoTextView.setOnClickListener(this);
        mHistoryTextView.setOnClickListener(this);
        mTopicTextView.setOnClickListener(this);
        mFristReadTextView.setOnClickListener(this);
        mAboutTextView.setOnClickListener(this);

        Drawable drawable1 = Utils.scaleDrawable(getActivity(), R.drawable.img_hm, 0.8f);
        mHomeTextView.setCompoundDrawables(drawable1, null, null, null);
        Drawable drawable2 = Utils.scaleDrawable(getActivity(), R.drawable.img_news, 0.8f);
        mInfoTextView.setCompoundDrawables(drawable2, null, null, null);
        Drawable drawable3 = Utils.scaleDrawable(getActivity(), R.drawable.img_ztjj, 0.8f);
        mTopicTextView.setCompoundDrawables(drawable3, null, null, null);
        Drawable drawable4 = Utils.scaleDrawable(getActivity(), R.drawable.img_syxx, 0.8f);
        mFristReadTextView.setCompoundDrawables(drawable4, null, null, null);
        Drawable drawable5 = Utils.scaleDrawable(getActivity(), R.drawable.img_about, 0.8f);
        mAboutTextView.setCompoundDrawables(drawable5, null, null, null);
    }

    @Override
    public void onClick(View v) {
        if (getActivity() instanceof CBHActivity) {
            CBHActivity cbhActivity = (CBHActivity) getActivity();
            Fragment fragment = cbhActivity.getContent();
            if (fragment instanceof CBHContentFragment) {
                CBHContentFragment content = (CBHContentFragment) fragment;
                if (v == mHomeTextView) {
                    content.setTitle(getString(R.string.menu_cbh));
                    content.switchContent(new CBHHomeFragment(mFragmentManager));
                } else if (v == mInfoTextView) {
                    content.setTitle(getString(R.string.menu_zxzx));
                    content.switchContent(new CBHListFragment(mFragmentManager));
                } else if (v == mTopicTextView) {
                    content.setTitle(getString(R.string.menu_ztjj));
                    content.switchContent(CBHGridViewFragment.newInstance());
                } else if (v == mHistoryTextView) {

                } else if (v == mFristReadTextView) {
                    content.setTitle(getString(R.string.menu_cfbd));
                    content.switchContent(new CBHFristReadFragment(mFragmentManager));
                } else if (v == mAboutTextView) {
                    content.setTitle(getString(R.string.menu_gyyy));
                    content.switchContent(new CBHAboutFragment(mFragmentManager));
                }
            }
            cbhActivity.getSlidingMenu().showContent();
        }
    }

    public static CBHMenu newInstance() {
        final CBHMenu cbhMenu = new CBHMenu();
        return cbhMenu;
    }

    public static CBHMenu newInstance(FragmentManager manager) {
        final CBHMenu cbhMenu = new CBHMenu(manager);
        return cbhMenu;
    }

}
